// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessable from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;
short choice,current,level;
string levelstr;
body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
init_special_item(0, "Bog Shrooms","Shaman Brup has sent Glup along with your party in search of these mushrooms. Now that you have them you must return them so he can heal the tribe's chieftain.");
init_special_item(1, "Instruction Manual", "This is a manual detailing how to use the panels controlling the flood gates in the sewers. Commands require various combinations of buttons, it all looks very complex.");
init_special_item(2, "Filthy Key", "This is a large brass key that you found on a dead body in the sewers. You washed it thoroughly, but it still looks dirty and feels oily to the touch.");
init_special_item(3, "Rusted Key", "You found this iron key in a large rats nest in the sewers of Keilan. Years spent in their damp nest has rusted it horribly.");
init_special_item(4,"Disruption Crystal","This gem, when plugged in to the power source in Mountainwatch, can disrupt the magic holding together all the golems there.");
init_special_item(5,"Tuchin's Note","Tuchin wrote this hastily scrawled note to tell you how to make the small adjustments necessary to work the disruption crystal.");

init_quest(1,"Stop the Golems.","Mayor White and all of Keilan have requested that you find the source of the golems, and put an end to them.");
init_quest(2,"Speak with the Mayor.","The Mayor of Keilan was the one that sent for you. Now you should speak with him to find out why.");
init_quest(3,"Speak with Shaman Brup.","Glup the swamp man wishes for you to travel to his village on the northern shore of Lake Tybor, and speak with his shaman about a quest.");
init_quest(4,"Find Ocher Bog Shrooms","The life of the swamp folk's chief depends on finding these shrooms. They are supposed to live in dark, wet locations, far from sunlight.");
init_quest(5,"Find a Power Source","If you find a place to plug in your disruption crystal, then you can destroy all the golems in Mountainwatch.");

init_special_abil(0,"Toggle Total Vision",12);
init_special_abil(1,"Toggle Sight Trace",13);
init_special_abil(2,"Glup's Level",14);

break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.

beginstate START_SCEN_STATE;
//boats and horses//
create_boat(0,2,19,36,0);
create_boat(1,2,20,29,0);
create_boat(2,2,16,19,0);
	// Initialize a few shops.
//Mack's smithy//
add_item_to_shop(1,373,4);
add_item_to_shop(1,81,2);
add_item_to_shop(1,73,1);
add_item_to_shop(1,36,1);
add_item_to_shop(1,144,2);
add_item_to_shop(1,115,2);
add_item_to_shop(1,134,1);
add_item_to_shop(1,57,2);

//Arum's arrows//
add_item_to_shop(2,87,50);
add_item_to_shop(2,100,100);
add_item_to_shop(2,102,100);
add_item_to_shop(2,103,50);
add_item_to_shop(2,106,100);
add_item_to_shop(2,108,40);
add_item_to_shop(2,92,5);
add_item_to_shop(2,97,5);

//Food store//
add_item_to_shop(3,4,15);
add_item_to_shop(3,6,5);
add_item_to_shop(3,397,10);
add_item_to_shop(3,398,10);
add_item_to_shop(3,399,3);

//Teach Pathfinder//
add_item_to_shop(4,5024,3);

//Junk store//
add_item_to_shop(5,203,1);
add_item_to_shop(5,(get_ran(1,24,149)),1);
add_item_to_shop(5,217,1);
add_item_to_shop(5,381,1);
add_item_to_shop(5,450,1);
add_item_to_shop(5,290,1);
add_item_to_shop(5,356,1);
add_item_to_shop(5,(get_ran(1,175,345)),1);
add_item_to_shop(5,219,1);
add_item_to_shop(5,38,1);

//Item of the Day//
//6//

//Potions//
add_item_to_shop(7,450,20);
add_item_to_shop(7,231,5);
add_item_to_shop(7,236,1);
add_item_to_shop(7,239,1);
add_item_to_shop(7,4012,1);
add_item_to_shop(7,4005,1);

//Fish//
add_item_to_shop(8,11,100);

//Swamp gear//
add_item_to_shop(9,453,2);
add_item_to_shop(9,455,3);
add_item_to_shop(9,461,4);
add_item_to_shop(9,462,20);

//Spells// 10
add_item_to_shop(10,2003,4);
add_item_to_shop(10,2004,4);
add_item_to_shop(10,2005,4);
add_item_to_shop(10,2008,4); 
add_item_to_shop(10,2010,3);
add_item_to_shop(10,2016,3);
add_item_to_shop(10,2017,2);
add_item_to_shop(10,2018,2);
add_item_to_shop(10,2019,2);
add_item_to_shop(10,3008,4);
add_item_to_shop(10,3010,4);
add_item_to_shop(10,3012,3);
add_item_to_shop(10,3013,3);
add_item_to_shop(10,3015,2);
add_item_to_shop(10,3017,2);
add_item_to_shop(10,3018,2);



break;


// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
if(char_ok(4) == 1)
	if(get_flag(250,5) != 0)
	{	if(get_flag(250,6) == 0)
			if(get_flag(250,5) >= 6)
			{	set_level(4,31);
				inc_flag(250,5,-6);
				inc_flag(250,6,1);
				clear_buffer();
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); } 
		if(get_flag(250,6) == 1)
			if(get_flag(250,5) >= 10)
			{	set_level(4,32);
				inc_flag(250,5,-10);
				inc_flag(250,6,1);
				clear_buffer();
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); }
		if(get_flag(250,6) == 2)
			if(get_flag(250,5) >= 14)
			{	set_level(4,33);
				inc_flag(250,5,-14);
				inc_flag(250,6,1);
				clear_buffer();
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); }
		if(get_flag(250,6) == 3)
			if(get_flag(250,5) >= 18)
			{	set_level(4,34);
				inc_flag(250,5,-18);
				inc_flag(250,6,1);
				clear_buffer();
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); }
		if(get_flag(250,6) == 4)
			if(get_flag(250,5) >= 20)
			{	set_level(4,35);
				inc_flag(250,5,-20);
				inc_flag(250,6,1);
				clear_buffer();
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); } 
		if(get_flag(250,6) == 5)
			if(get_flag(250,5) >= 22)
			{	set_level(4,36);
				inc_flag(250,5,-22);
				inc_flag(250,6,1); 
				clear_buffer();
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); }
		if(get_flag(250,6) == 6)
			if(get_flag(250,5) >= 24)
			{	set_level(4,37);
				inc_flag(250,5,-24);
				inc_flag(250,6,1);
				clear_buffer(); 
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); } 
		if(get_flag(250,6) == 7)
			if(get_flag(250,5) >= 26)
			{	set_level(4,38);
				inc_flag(250,5,-26);
				inc_flag(250,6,1); 
				clear_buffer(); 
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); }
		if(get_flag(250,6) == 8)
			if(get_flag(250,5) >= 28)
			{	set_level(4,39);
				inc_flag(250,5,-28);
				inc_flag(250,6,1); 
				clear_buffer(); 
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); } 
		if(get_flag(250,6) == 9)
			if(get_flag(250,5) >= 30)
			{	set_level(4,40);
				inc_flag(250,5,-30);
				inc_flag(250,6,1); 
				clear_buffer(); 
				append_string("Glup is now level ");
				append_number(get_level(4));
				append_string("!");
				get_buffer_text(levelstr);
				print_str_color(levelstr,2);
				play_sound(26); }
}

		
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
	reset_dialog();
	add_dialog_str(0,"You flip through the journal. It is very long, practically a volume, and written by Janok. It details his flight to the sewers to escape pursuit. He never mentions why he is purused, or by whom.",0);
	add_dialog_str(1,"One passage stands out to you:",0);
	add_dialog_str(2,"Lest I forget",200);
	add_dialog_str(3,"_They have driven me out. They killed the love of my life, and now they hunt for me as well. Never again will I hear her sweet voice lifted in song or gaze upon her radiant beauty, for they have taken her from me.",40);
	add_dialog_str(4,"She chose to love me, but they were jealous, the gods themselves envied her beauty and now they have all conspired to take her from me.",40);
	add_dialog_str(5,"My revenge will be complete, I will make the people of this accursed hole rue the day they touched my love. Their howls will be sweeter to my ears than even the voice of my darling Dilecia._",40);
	add_dialog_str(6,"This begins pages of rambling about Janok's retribution. The writings become increasingly insane as you read on.",0);
	add_dialog_choice(0,"OK.");	
	if(run_dialog(1) == 1) 
	{	set_flag(250,8,1);
		end(); }
break;

beginstate 11;
	reset_dialog();
	add_dialog_str(0,"You unfurl the scroll and recognize the same handwriting that wrote all the other logs and papers from the lab in Smolt.",0);
	add_dialog_str(1,"Jszoula Keep - Would offer good staging groung against Keilan. Also could be noticed easily. Not good choice.",35);
	add_dialog_str(2,"Mountainwatch - Very isolated, large quarry nearby. Good selection. (The author came back and wrote a red check here. Looks like he made up his mind.)",35);
	add_dialog_str(3,"Subterranean caves - Interferes with communication frequencies, not a good choice.",35);
	add_dialog_str(4,"The paper seems to be an analysis of possible locations to establish a headquarters, could be useful in tracking down whoever is responsible for the golems.",0);
add_dialog_choice(0,"OK.");
	if(run_dialog(1) == 1) {
		set_flag(7,9,1);
		end(); }
break;

beginstate 12;
	change_custom_abil_uses(who_used_custom_abil(),0,1);
	if(get_flag(8,1) == 1) {
		reset_dialog();
		add_dialog_str(0,"Would you like to turn off total visibility?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No, leave it how it is.");
		choice = run_dialog(1);
		if(choice == 1) {
			set_total_visibility(0);
			set_flag(8,1,0);
			end(); }
		if(choice == 2)
			end();
}
	if(get_flag(8,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"Would you like to turn on total visibility?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No, leave it how it is.");
		choice = run_dialog(1);
		if(choice == 1) {
			set_total_visibility(1);
			set_flag(8,1,1);
			end(); }
		if(choice == 2)
			end();
}
break;

beginstate 13;
	change_custom_abil_uses(who_used_custom_abil(),1,1);
	if(get_flag(8,5) == 1) {
		reset_dialog();
		add_dialog_str(0,"Would you like to turn off site trace?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No, leave it how it is.");
		choice = run_dialog(1);
		if(choice == 1) {
			set_flag(8,5,0);
			set_flag(8,6,1);
			end(); }
		if(choice == 2)
			end();
}
	if((get_flag(8,5) == 0)) {
		reset_dialog();
		add_dialog_str(0,"Sight trace causes the floors to change colors wherever the golems can see. Do you want to turn it on?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No, leave it how it is.");
		choice = run_dialog(1);
		if(choice == 1) {
			set_flag(8,5,1);
			end(); }
		if(choice == 2)
			end();
}
break;

beginstate 14;
change_custom_abil_uses(who_used_custom_abil(),2,1);
if(get_flag(250,1) == 1)
{	print_str("Glup is dead.");
	end(); }
if(get_flag(250,0) == 0)
{	print_str("Glup is not with the party.");
	end(); }
	clear_buffer(); 
	append_string("Glup is currently level ");
	append_number(get_level(4));
	append_string(".");
	get_buffer_text(levelstr);
	print_str_color(levelstr,2);
end();
break;
